package foodmaterial.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import foodmaterial.action.valid.TrueFalseValid;
import foodmaterial.utils.Constants;
import org.hibernate.validator.constraints.Length;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;

public class SysUser implements UserDetails, Serializable {
    private static final long serialVersionUID = 6524685014580359022L;
    private Long id ;
    @NotBlank(message = "用户账号不能为空")
    @Length(min = 1,max=20,message = "用户账号最长{max}个字符，最短{min}个字符")
    private String account ;
    @NotBlank(message = "用户名称不能为空")
    private String name ;
    private String password ;
    private String oldPassword ;
    private String confirmPassword ;
    @JsonFormat(pattern= Constants.DEFAULT_DATE_TIME_FORMAT,timezone="GMT+8")
    private Date lastLoginTime ;
    private Boolean userData = Boolean.TRUE ;
    /**
     * 账号是否可用
     */
    @JsonProperty("enabled")
    @TrueFalseValid(message = "值为[true]或者[false]")
    private Boolean selfEnabled  ;
    /**
     * 账号没过期
     */
    @JsonProperty("accountNonExpired")
    @TrueFalseValid(message = "值为[true]或者[false]")
    private Boolean selfAccountNonExpired  ;
    /**
     * 账号没锁定
     */
    @JsonProperty("accountNonLocked")
    @TrueFalseValid(message = "值为[true]或者[false]")
    private Boolean selfAccountNonLocked ;
    /**
     * 证书（密码）没过期
     */
    @JsonProperty("credentialsNonExpired")
    @TrueFalseValid(message = "值为[true]或者[false]")
    private Boolean selfCredentialsNonExpired;

    @JsonFormat(pattern=Constants.DEFAULT_DATE_TIME_FORMAT,timezone="GMT+8")
    private Date createTime ;

    @JsonFormat(pattern=Constants.DEFAULT_DATE_TIME_FORMAT,timezone="GMT+8")
    private Date updateTime ;

    private String creator  ;

    private String updateUser ;

    /**
     * 用户使用的数据库
     */
    private String db ;

    /**
     * 用户类型
     */
    @NotBlank(message = "用户职位分类不能为空")
    private String userType ;

    private String companyName ;

    private boolean checked ;

    private Boolean customerLogin ;//如果不为空，表示是配送客户登录

    private String foodSupplyType ;

    /**
     * 权限列表
     */
    private List<GrantedAuthority> grantedAuthorities ;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    @Override
    public String getUsername() {
        return this.account;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setGrantedAuthorities(List<GrantedAuthority> grantedAuthorities) {
        this.grantedAuthorities = grantedAuthorities ;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return grantedAuthorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Date getLastLoginTime() {
        return lastLoginTime;
    }

    public void setLastLoginTime(Date lastLoginTime) {
        this.lastLoginTime = lastLoginTime;
    }

    public Boolean getUserData() {
        return userData;
    }

    public void setUserData(Boolean userData) {
        this.userData = userData;
    }

    @Override
    public boolean isEnabled() {
        return selfEnabled;
    }

    @Override
    public boolean isAccountNonExpired() {
        return selfAccountNonExpired;
    }

    @Override
    public boolean isAccountNonLocked() {
        return selfAccountNonLocked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return this.selfCredentialsNonExpired;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getCreator() {
        return creator;
    }

    public void setCreator(String creator) {
        this.creator = creator;
    }

    public String getUpdateUser() {
        return updateUser;
    }

    public void setUpdateUser(String updateUser) {
        this.updateUser = updateUser;
    }

    public String getDb() {
        return db;
    }

    public void setDb(String db) {
        this.db = db;
    }

    public String getOldPassword() {
        return oldPassword;
    }

    public void setOldPassword(String oldPassword) {
        this.oldPassword = oldPassword;
    }

    public String getConfirmPassword() {
        return confirmPassword;
    }

    public void setConfirmPassword(String confirmPassword) {
        this.confirmPassword = confirmPassword;
    }

    public Boolean getSelfEnabled() {
        return selfEnabled;
    }

    public void setSelfEnabled(Boolean selfEnabled) {
        this.selfEnabled = selfEnabled;
    }

    public Boolean getSelfAccountNonExpired() {
        return selfAccountNonExpired;
    }

    public void setSelfAccountNonExpired(Boolean selfAccountNonExpired) {
        this.selfAccountNonExpired = selfAccountNonExpired;
    }

    public Boolean getSelfAccountNonLocked() {
        return selfAccountNonLocked;
    }

    public void setSelfAccountNonLocked(Boolean selfAccountNonLocked) {
        this.selfAccountNonLocked = selfAccountNonLocked;
    }

    public Boolean getSelfCredentialsNonExpired() {
        return selfCredentialsNonExpired;
    }

    public void setSelfCredentialsNonExpired(Boolean selfCredentialsNonExpired) {
        this.selfCredentialsNonExpired = selfCredentialsNonExpired;
    }

    public String getUserType() {
        return userType;
    }

    public void setUserType(String userType) {
        this.userType = userType;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public boolean isChecked() {
        return checked;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }

    public Boolean getCustomerLogin() {
        return customerLogin;
    }

    public void setCustomerLogin(Boolean customerLogin) {
        this.customerLogin = customerLogin;
    }

    public String getFoodSupplyType() {
        return foodSupplyType;
    }

    public void setFoodSupplyType(String foodSupplyType) {
        this.foodSupplyType = foodSupplyType;
    }
}
